/*
 * Copyright (c) 2012-2013, CS Bakery. All rights reserved.
 */

package csBakery;

import java.util.Vector;

/*
 * 	@release Final Release
 *	@author  Leung Ho Yan
 *	@version 2.0.2
 *
 * 	@release Release 2
 *	@author  Yip Tak Wai
 *	@version 2.0.0
 *
 * 	@release Release 1
 *	@author  Yip Tak Wai
 *	@version 1.0.1
 */

public class Stock {

	private final static int PRODUCTNO = 10;
	private static Vector<Product> v;
		
	public Stock(){
		v = new Vector<Product>(PRODUCTNO);
	}
		
	public Vector<String> getStockProductList(){
		Vector<String> vector = new Vector<String>(PRODUCTNO);
		for (int i = 0; i < v.size(); i++){
			vector.add(v.elementAt(i).getName());
		}
		return vector;
	}
		
	public Product getProductInformation(String name){
		Product temp = null;
		for (int i = 0; i < v.size(); i++ ){
			if (name.equals(v.elementAt(i).getName())){
				temp = v.elementAt(i);
				break;
			}
		}
		if (temp == null){
			System.out.print("Product not found.");
		}
		return temp;
	}

	public void setProductQuantity(String name, int number){
		for (int i = 0; i < v.size(); i++ ){
			if (name.equals(v.elementAt(i).getName())){
				v.elementAt(i).setQuantity(number);
				break;
			}
		}			
	}
	
	public int getProductQuantity(String name){
		for (int i = 0; i < v.size(); i++ ){
			if (name.equals(v.elementAt(i).getName())){
				return v.elementAt(i).getQuantity();
			}
		}
		return -1;
	}
		
	public void addItem(String name, int qty){
		v.add(new Product(name, qty));
	}
	
	public void clearAllItems(){
		v.clear();
	}
		
	public String toString(){
		String str = "";
		for (int i = 0; i < v.size(); i++){
			str += v.elementAt(i).getName() + " " + v.elementAt(i).getQuantity() + "\n";
		}
		return str;
	}
}
